package com.xx.bysj.controller;

import com.xx.bysj.aop.LogAop;
import com.xx.bysj.aop.LogConsts;
import com.xx.bysj.dto.HnMenu;
import com.xx.bysj.dto.HnUser;
import com.xx.bysj.service.MenuService;
import com.xx.bysj.utils.MenuResultUtils;
import com.xx.bysj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 目录
     *
     * @return
     */
    @RequestMapping("/show")
    @ResponseBody
    @LogAop(actionName = "展示目录",actionType = LogConsts.ACTION_QUERY)
    public String showMenu(HnUser user, Authentication authentication, HttpServletRequest request) {
        user.setUserName(authentication.getName());
        return menuService.showMenu(user);
    }

    /**
     * 菜单管理
     * @return
     */
    @RequestMapping("/manage")
    @ResponseBody
    @LogAop(actionName = "菜单管理",actionType = LogConsts.ACTION_QUERY)
    public MenuResultUtils menuManage(){
        return menuService.menuManage();
    }

    /**
     * 查询类型
     * @return
     */
    @RequestMapping("/queryType")
    @ResponseBody
    @LogAop(actionName = "查询类型",actionType = LogConsts.ACTION_QUERY)
    public List<HnMenu> queryType(){
        return menuService.queryType();
    }

    /**
     * 查询所有的节点
     * @return
     */
    @RequestMapping("/queryNode")
    @ResponseBody
    @LogAop(actionName = "查询所有节点",actionType = LogConsts.ACTION_QUERY)
    public List<HnMenu> queryNode(){
        return menuService.queryNode();
    }

    /**
     * 跟新节点
     * @return
     */
    @RequestMapping("/updateMenu")
    @ResponseBody
    @LogAop(actionName = "更新节点",actionType = LogConsts.ACTION_UPDATE)
    public Result updateMenu(HnMenu menu,Authentication authentication){
        return menuService.updateMenu(menu,authentication);
    }

    /**
     * 新增节点
     * @param menu
     * @return
     */
    @RequestMapping("/addMenu")
    @ResponseBody
    @LogAop(actionName = "新增节点",actionType = LogConsts.ACTION_ADD)
    public Result addMenu(HnMenu menu,Authentication authentication){
        return menuService.addMenu(menu,authentication);
    }

    /**
     * 删除节点
     * @param title
     * @return
     */
    @RequestMapping("/deleteMenu")
    @ResponseBody
    @LogAop(actionName = "删除节点",actionType = LogConsts.ACTION_DELETE)
    public Result deleteMenu(String title,Authentication authentication){
        return menuService.deleteMenu(title,authentication);
    }

}
